import request from '@/utils/request'

// 查询所有数据
export function getAllData(query) {
  return request({
    url: '/indicator/dealIndicatorPredict/getAllData',
    method: 'get',
    params: query
  })
}

// 获取当前项目是否需要进行初始化.
export function initCurrentData(dealId, businessId) {
  if (businessId === '' || businessId === null || businessId === undefined) {
    businessId = '-999'
  }
  if (dealId === '' || dealId === null || dealId === undefined) {
    dealId = '-9999'
  }
  return request({
    url: '/indicator/dealIndicatorPredict/initCurrentData/' + dealId + '/' + businessId,
    method: 'get'
  })
}

// 查询盈利预测配置列表
export function listDealIndicatorPredict(query) {
  return request({
    url: '/indicator/dealIndicatorPredict/list',
    method: 'get',
    params: query
  })
}

export function findDealPredict(query) {
  return request({
    url: '/indicator/dealIndicatorPredict/findDealPredict',
    method: 'get',
    params: query
  })
}

// 查询盈利预测配置详细
export function getDealIndicatorPredict(id) {
  return request({
    url: '/indicator/dealIndicatorPredict/' + id,
    method: 'get'
  })
}

// 查询盈利预测配置详细
export function getDealIndicatorPredictByCode(code, businessId, typeId) {
  if (businessId === '' || businessId === undefined || businessId === null) {
    businessId = '-1'
  }
  if (typeId === '' || typeId === null || typeId === undefined) {
    typeId = '-1'
  }
  const data = {
    code: code,
    businessId: businessId,
    typeId: typeId
  }
  return request({
    url: '/indicator/dealIndicatorPredict/getDealIndicatorPredictByCode',
    method: 'post',
    data: data
  })
}

// 保存盈利预测配置
export function saveDealIndicatorPredict(data) {
  return request({
    url: '/indicator/dealIndicatorPredict/save',
    method: 'post',
    data: data
  })
}

// 删除盈利预测配置
export function delDealIndicatorPredict(id) {
  return request({
    url: '/indicator/dealIndicatorPredict/' + id,
    method: 'delete'
  })
}

// 导出盈利预测配置
export function exportDealIndicatorPredict(query) {
  return request({
    url: '/indicator/dealIndicatorPredict/export',
    method: 'get',
    params: query
  })
}

// 批量排序
export function updateSort(data) {
  return request({
    url: '/indicator/dealIndicatorPredict/updateSort',
    method: 'post',
    data: data
  })
}

export const evalStr = fn => {
  // 一个变量指向Function，防止有些前端编译工具报错
  try {
    return new Function('return ' + fn)()
  } catch (e) {
    console.error(e)
    return 0
  }
}

export function syncToDeal(data) {
  return request({
    url: '/indicator/dealIndicatorPredict/syncToDeal',
    method: 'post',
    data: data
  })
}
